package org.puremvc.as3.fi.patterns.observer 
{
	import org.puremvc.as3.multicore.interfaces.INotifier;
	import org.puremvc.as3.fi.interfaces.IFacadeInjected;
	import org.puremvc.as3.fi.interfaces.IInjectableFacade;
	
	/**
	 * @author a.fell
	 */
	public class Notifier implements INotifier, IFacadeInjected 
	{
		protected var facade : IInjectableFacade;
		
		public function setFacade(facade : IInjectableFacade) : void
		{
			this.facade = facade;
		}

		public function sendNotification( notificationName:String, body:Object=null, type:String=null ):void 
		{
			if (facade != null) 
				facade.sendNotification( notificationName, body, type );
		}
		
		/**
		 * Initialize this INotifier instance.
		 * <P>
		 * This is how a Notifier gets its multitonKey. 
		 * Calls to sendNotification or to access the
		 * facade will fail until after this method 
		 * has been called.</P>
		 * 
		 * <P>
		 * Mediators, Commands or Proxies may override 
		 * this method in order to send notifications
		 * or access the Multiton Facade instance as
		 * soon as possible. They CANNOT access the facade
		 * in their constructors, since this method will not
		 * yet have been called.</P> 
		 * 
		 * @param key the multitonKey for this INotifier to use
		 */
		public function initializeNotifier( key:String ):void
		{
			multitonKey = key;
		}
		
		// The Multiton Key for this app
		protected var multitonKey : String;
		
		public function hasFacade() : Boolean
		{
			return facade != null;
		}
	}
}
